/**
 * Created by chenqiailai on 17/9/14.
 */



seller = getUrlParam('channel');
wxid = getUrlParam('openid');
// wxid ='o4WARv1h7DiAr_Ipydx-dEEwp4aU';
result.wxid = wxid;
result.channel = seller;
console.log(seller);
console.log(wxid);

$.ajax({
    url:'lib/img.json',
    type:'GET',
    async:true,
    timeout:5000,
    dataType:'json',
    success:function(data,textStatus,jqXHR){
        // console.log(data);
        var imgzip = data;
        // console.log(imgzip);

        var html;
        $.each(imgzip,function(index,value) {

            if(index == 0){
                html = '<div class="score-modal" id="first-score"><span class="little-line"></span>';
            }else{
                html = '<div class="score-modal" id="' + index + '"><span class="little-line"></span>';
            };

            html +='<div class="score-img">';
            html +='<img id="img' +value.id + '" src="' + value.imageurl+ '" onclick="return false" ></div>';
            html +='<span class="little-line"></span>';
            html +='<div class="rangeSlider"><input type="hidden" class="slider-input" value="2.5" id="'+ value.id +'"/></div></div>';
            $(html).appendTo('.score-box');
        });

    },
    error:function(xhr,textStatus){

        console.log(xhr);
        console.log(textStatus);
    },
    complete:function(){
        // console.log('结束');

        $('.slider-input').each(function () {
            $(this).jRange({
                from: 0,
                to: 5,
                setValue: 3,
                step: 1,
                scale: [0,5],
                format: '%s',
                showLabels: true,
                showScale: true
            })
        });


    }

});
//

var open ={
    openid:wxid
};
var allinfo = {};
$.ajax({
    url:'http://wx.zhishixia.com/wechat/getuser',
    type:'POST',
    async:true,
    timeout:5000,
    data:open,
    dataType:'json',
    success:function(data,textStatus,jqXHR){
        console.log('wx');
        console.log(data);
        allinfo.wxuser = data;
        console.log(allinfo.wxuser);

    },
    error:function(xhr,textStatus){

        console.log(xhr);
        console.log(textStatus);
    },
    complete:function(){
        // console.log('结束');

    }

});




$(function(){
    scoreresult = [];
    //获得打分
    $(".score-btn").click(function(){
        var allrange = $('.slider-input');
        $(allrange).each(function (i) {
            var score = {};
            var id = $(this).attr('id');
            var scoreNum = $(this).val();
            score[id] = scoreNum;
            scoreresult[i] = score;
        });
        console.log(scoreresult);
        allinfo.nowscore = scoreresult;

        console.log(allinfo);

        $.ajax({
            headers: {
                Accept: 'application/json, text/plain, */*'
            },
            url : 'http://www.fraplus.net/products',
            type: "POST",
            data : JSON.stringify(allinfo),//Requerst Payload
            dataType:'json',
            contentType:'application/json; charset=utf-8',

            success: function(data, textStatus, jqXHR){
                console.log('ok');
                console.log(data);
                //data - response from server
            },
            error: function (jqXHR, textStatus, errorThrown){
                console.log('fail');
                console.log(errorThrown);
            }
        });

        location.hash = vipspa.stringify('home-1');
    });



});